#include "soarequest.h"
//


SoaRequest::SoaRequest( QObject * parent )
	: QObject( parent )
{
	setObjectName(QString::fromUtf8("SoaRequest"));
	Cache(WORK_TICINO_SESSION);
	ResetSession();
	currentID = -1;
	Save_append_Session();
}

void SoaRequest::Login()
{
	qDebug() << "### soa Login ACTION ###################";
	QString Stream_0 ="PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz4KPFNPQVAtRU5WOkVudmVsb3BlIHhtbG5zOlNPQVAtRU5WPSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VudmVsb3BlLyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM6bnMxPSJodHRwOi8vd3MudGljaW5vLXRvdXJpc20uY2gvd3NkbCIgeG1sbnM6eHNkPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSIgeG1sbnM6U09BUC1FTkM9Imh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3NvYXAvZW5jb2RpbmcvIiA+CiAgICAgPFNPQVAtRU5WOkJvZHk+CiAgICAgICAgICA8bnMxOmxvZ2luPgogICAgICAgICAgICAgICA8dXNlcm5hbWU+X1VTRVJfPC91c2VybmFtZT4KICAgICAgICAgICAgICAgPHBhc3N3b3JkPl9QQVNTXzwvcGFzc3dvcmQ+CiAgICAgICAgICA8L25zMTpsb2dpbj4KICAgICA8L1NPQVAtRU5WOkJvZHk+CjwvU09BUC1FTlY6RW52ZWxvcGU+";
	QString Stream = fromBase64(Stream_0);
	        Stream = Stream.replace("_PASS_",decodeBase64(setter.value("tijava/pass").toString()));
	        Stream = Stream.replace("_USER_",decodeBase64(setter.value("tijava/user").toString()));
	ResetSession();
	Send(Stream,_URLSYSTEM_,1);
}

void SoaRequest::Logout()
{
	qDebug() << "### soa Logout ACTION ###################";
	QString Stream_0 ="PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz4KPFNPQVAtRU5WOkVudmVsb3BlIHhtbG5zOlNPQVAtRU5WPSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VudmVsb3BlLyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM6bnMxPSJodHRwOi8vd3MudGljaW5vLXRvdXJpc20uY2gvd3NkbCIgeG1sbnM6eHNkPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSIgeG1sbnM6U09BUC1FTkM9Imh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3NvYXAvZW5jb2RpbmcvIiA+CiAgICAgPFNPQVAtRU5WOkJvZHk+CiAgICAgICAgICA8bnMxOmxvZ291dD4KICAgICAgICAgICAgICAgPGF1dGhlbnRpY2F0ZWRVc2VyPgogICAgICAgICAgICAgICAgICAgIDx0b2tlbj5fU0VTU0lPTl88L3Rva2VuPgogICAgICAgICAgICAgICAgICAgIDx1c2VyPgogICAgICAgICAgICAgICAgICAgICAgICAgPGFjY291bnRDcmVhdGlvbj4yMDA4LTA0LTExVDIwOjIwOjUyWjwvYWNjb3VudENyZWF0aW9uPgogICAgICAgICAgICAgICAgICAgICAgICAgPGFjY291bnRFeHBpcmF0aW9uPjIwMDgtMDQtMTFUMjA6MjA6NTJaPC9hY2NvdW50RXhwaXJhdGlvbj4KICAgICAgICAgICAgICAgICAgICAgICAgIDxkaXNhYmxlPmZhbHNlPC9kaXNhYmxlPgogICAgICAgICAgICAgICAgICAgICAgICAgPGVtYWlsLz4KICAgICAgICAgICAgICAgICAgICAgICAgIDxmaXJzdE5hbWUvPgogICAgICAgICAgICAgICAgICAgICAgICAgPGphYXNSb2xlLz4KICAgICAgICAgICAgICAgICAgICAgICAgIDxsYXN0TG9nb24+MjAwOC0wNC0xMVQyMDoyMDo1Mlo8L2xhc3RMb2dvbj4KICAgICAgICAgICAgICAgICAgICAgICAgIDxsYXN0TmFtZS8+CiAgICAgICAgICAgICAgICAgICAgICAgICA8bG9naW4vPgogICAgICAgICAgICAgICAgICAgICAgICAgPHBhc3N3b3JkLz4KICAgICAgICAgICAgICAgICAgICAgICAgIDx3ZWJTaXRlSWRzPjA8L3dlYlNpdGVJZHM+CiAgICAgICAgICAgICAgICAgICAgICAgICA8d29ya3NwYWNlPjA8L3dvcmtzcGFjZT4KICAgICAgICAgICAgICAgICAgICA8L3VzZXI+CiAgICAgICAgICAgICAgIDwvYXV0aGVudGljYXRlZFVzZXI+CiAgICAgICAgICA8L25zMTpsb2dvdXQ+CiAgICAgPC9TT0FQLUVOVjpCb2R5Pgo8L1NPQVAtRU5WOkVudmVsb3BlPg==";
	QString Stream = fromBase64(Stream_0);
	Stream = Stream.replace("_SESSION_",WebSessionCurrent);
	qDebug() << "### soa logout -> " << WebSessionCurrent;
	Send(Stream,_URLSYSTEM_,0);
	ResetSession();
}

void SoaRequest::ListaCase( int tipo )
{
	  Tipovigore = tipo;
	  QString TipoCasa;
		TipoCasa.setNum(tipo);
    QString Stream_0 ="PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz4KPFNPQVAtRU5WOkVudmVsb3BlIHhtbG5zOlNPQVAtRU5WPSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VudmVsb3BlLyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM6bnMxPSJodHRwOi8vd3MudGljaW5vLXRvdXJpc20uY2gvd3NkbCIgeG1sbnM6bnMzPSJodHRwOi8vamF4Yi5kZXYuamF2YS5uZXQvYXJyYXkiIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zOlNPQVAtRU5DPSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VuY29kaW5nLyIgPgogICAgIDxTT0FQLUVOVjpCb2R5PgogICAgICAgICAgPG5zMTpmaW5kTGlnaHRIb3VzZXM+CiAgICAgICAgICAgICAgIDx0b2tlbj5fU0VTU0lPTl88L3Rva2VuPgogICAgICAgICAgICAgICA8Y3JpdGVyaWE+CiAgICAgICAgICAgICAgICAgICAgPGhvdXNlVHlwZUlkcz5fVElQT0NBU0FfPC9ob3VzZVR5cGVJZHM+CiAgICAgICAgICAgICAgICAgICAgPHdlYlNpdGVJZHM+MTY8L3dlYlNpdGVJZHM+CiAgICAgICAgICAgICAgIDwvY3JpdGVyaWE+CiAgICAgICAgICA8L25zMTpmaW5kTGlnaHRIb3VzZXM+CiAgICAgPC9TT0FQLUVOVjpCb2R5Pgo8L1NPQVAtRU5WOkVudmVsb3BlPg==";
	  QString Stream = fromBase64(Stream_0);
	  Stream = Stream.replace("_SESSION_",WebSessionCurrent);
	  Stream = Stream.replace("_TIPOCASA_",TipoCasa);
	  Send(Stream,_URLHOUSES_,11);
}

QDomDocument SoaRequest::Casa_Doc( const int ipid )
{
	  const QString idsx = QString("%1").arg(ipid);
	  QString Stream_0 ="PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz4KPFNPQVAtRU5WOkVudmVsb3BlIHhtbG5zOlNPQVAtRU5WPSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VudmVsb3BlLyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM6bnMxPSJodHRwOi8vd3MudGljaW5vLXRvdXJpc20uY2gvd3NkbCIgeG1sbnM6bnMzPSJodHRwOi8vamF4Yi5kZXYuamF2YS5uZXQvYXJyYXkiIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zOlNPQVAtRU5DPSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VuY29kaW5nLyIgPgogICAgIDxTT0FQLUVOVjpCb2R5PgogICAgICAgICAgPG5zMTpnZXRIb3VzZT4KICAgICAgICAgICAgICAgPHRva2VuPl9TRVNTSU9OXzwvdG9rZW4+CiAgICAgICAgICAgICAgICA8aG91c2VJdGVtSWQ+X0lEQ0FTQV88L2hvdXNlSXRlbUlkPgogICAgICAgICAgICAgICA8d2ViU2l0ZUlkcz4xNjwvd2ViU2l0ZUlkcz4KICAgICAgICAgICAgICAgPG1lcmdlPmZhbHNlPC9tZXJnZT4KICAgICAgICAgIDwvbnMxOmdldEhvdXNlPgogICAgIDwvU09BUC1FTlY6Qm9keT4KPC9TT0FQLUVOVjpFbnZlbG9wZT4=";
  	QString Stream = fromBase64(Stream_0);
	  Stream = Stream.replace("_SESSION_",WebSessionCurrent);
	  Stream = Stream.replace("_IDCASA_",idsx);
		QDomDocument doc_entra;   ///// 
	  QDomDocument doc_null;   ///// 
	  bool prendi = false;
	  QString errorStr;
    int errorLine, errorColumn, position;
    if (doc_entra.setContent(Stream,false, &errorStr, &errorLine, &errorColumn)) {
      return doc_entra;
    } else {
			return doc_null;
		}
}




void SoaRequest::Send( QString streams , QUrl url , const int memid )
{
	    /////////////qDebug() << "### soa send first -> " << memid << " " << url;
	        if (url.port() < 1) {
              url.setPort(80);
					}
	   currenturl = url;
     currentID = memid;
     QString errorStr;
     int errorLine, errorColumn, position;
	   if (!doc.setContent(streams,false, &errorStr, &errorLine, &errorColumn)) {
      currentID = 0;
		  emit SendError();
			return;
     } else {
			 
			 if (memid !=1 && WebSessionCurrent.endsWith("00000000")) {
				 /* no session!!! */
				 qDebug() << "### no valid session  -> " << WebSessionCurrent << " - " << memid;
				 emit SendError();
				 ResetSession();
			   return;
			 }
			 
			 QDateTime timer1( QDateTime::currentDateTime() ); 
			 
			 
			 
			 ////////////qDebug() << "### soa send 1  -> " << WebSessionCurrent;
			 QByteArray *bites = new QByteArray();
			 bites->append(doc.toByteArray(1)); 
			 fwriteutf8(WORK_TICINO_SESSION + "request_" +timer1.toString ("d_M_yy_h.m.s")+".txt",doc.toString(5));
			 buffer_send = new QBuffer(bites,this);
			 if (!buffer_send->open(QIODevice::ReadWrite)) {
				return;
				}
				buffer_incomming = new QBuffer(this);
				if (!buffer_incomming->open(QIODevice::ReadWrite)) {
				return;
				}
			 
			 header.setRequest("POST",url.path(),1,1);
			 header.setValue("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
			 header.setValue("Accept-Encoding","gzip,deflate,qcompress");
			 header.setValue("Connection","keep-alive");
			 header.setValue("Content-Type","text/xml; charset=utf-8");
			 header.setValue("Handler","Ajax=4");
			 header.setValue("Host",url.host());
			 header.setValue("Autor","QT4 - Crosskern.com");
			 header.setValue("User-Agent","ETV-Vallemaggia-Sincro");
			 ShttpR = new QHttp(url.host(),url.port(),this); /* ############################ htttp ############################## */
			 /////////ShttpR->setHost(url.host());
				current_HTTP_ID = ShttpR->request(header,buffer_send,buffer_incomming);
			   connect(ShttpR, SIGNAL(done(bool)), this, SLOT(Exitdone(bool)));
         connect(ShttpR, SIGNAL(dataReadProgress(int, int)), this, SLOT(ReciverStatus(int, int)));
         connect(ShttpR, SIGNAL(readyRead(const QHttpResponseHeader &)), this, SLOT(SaveData(const QHttpResponseHeader &)));
	       connect(ShttpR, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), this, SLOT(SaveData(const QHttpResponseHeader &)));
			   connect(ShttpR, SIGNAL(stateChanged(int)), this, SLOT(SnState(int)));
				 
		 }
}
void SoaRequest::SnState( const int state )
{
	qDebug() << "### SnState  -> " << state;
}

void SoaRequest::Exitdone( bool e  )
{
    const QHttpResponseHeader headers = ShttpR->lastResponse();
	  headercode = headers.statusCode();
	  QStringList headerin = headers.keys();
    for (int i = 0; i < headerin.size(); ++i) {
			const QString HeaderValue = headers.value(headerin.at(i));
			const QString name = headerin.at(i);
			if (name == "content-encoding") {
				////////qDebug() << "### HeaderValue  -> " << HeaderValue;
				Logout();
				return;
			}
			  
    }
		
	  qDebug() << "### headercode Exitdone  -> " << headercode;
		qDebug() << "### current_ShttpR_ID  -> " << current_HTTP_ID;
	/////////////qDebug() << "### reasonPhrase()   -> " << ShttpR->lastResponse().reasonPhrase();
	
	
	  if (headercode == 200) {
			QString errorStr;
      int errorLine, errorColumn, position;
	        if (!doc.setContent(buffer_incomming->data(),false, &errorStr, &errorLine, &errorColumn)) {
          currentID = 0;
					Logout();
		      emit SendError();
			    return;
          }
					QDomElement root = doc.documentElement();  
					root.setAttribute ("oggettotipo",Tipovigore);
          root.setAttribute ("headercode",headercode);
          root.setAttribute ("currentID",currentID);
	        root.setAttribute ("current_HTTP_ID",current_HTTP_ID);
					root.setAttribute ("host",currenturl.host());
					root.setAttribute ("path",currenturl.path());
					pIN = doc.toString(5);
					QDateTime timer1( QDateTime::currentDateTime() ); 
          fwriteutf8(WORK_TICINO_SESSION + "incomming_" +timer1.toString ("d_M_yy_h.m.s.zzz")+".txt",doc.toString(5));
					
		} else {
			Logout();
			emit SendError();
			return;
		}
		
	  if (pIN.size() > 0 && currentID == 1) {
		   SetSessionId(pIN);
			 if (!WebSessionCurrent.endsWith("00000000")) {
				  emit SessionStatus(true);
				  return;
			 } else {
				 Logout();
				 emit SendError();
				 ShttpR->deleteLater();
			   buffer_incomming->deleteLater();
		     buffer_send->deleteLater();
			   currentID = -1;
				 ResetSession();
			 }
			 
		   ShttpR->deleteLater();
		} else if (currentID == 0) {
			ShttpR->deleteLater();
			buffer_incomming->deleteLater();
		  buffer_send->deleteLater();
			emit SessionStatus(false);
			currentID = -1;
			return;
		}
		qDebug() << "### size in" << pIN.size() << " currentID " << currentID;
    emit LastDone(currentID);
		buffer_incomming->deleteLater();
		buffer_send->deleteLater();
}
void SoaRequest::ReciverStatus( int fatto , int tot )
{
    qDebug() << "### ReciverStatus b." << fatto << " t." << tot;
}

void SoaRequest::SaveData(const QHttpResponseHeader &responseHeader )
{
    headercode = ShttpR->lastResponse().statusCode();
	 ///////// qDebug() << "### SaveData -> " << headercode;
	
    QStringList headerin = responseHeader.keys();
	  HeaderIncome.clear();
    for (int i = 0; i < headerin.size(); ++i) {
			const QString HeaderValue = responseHeader.value(headerin.at(i));
			  //////////////qDebug() << "### HeaderValue" << HeaderValue;
			  HeaderIncome.insert(headerin.at(i),HeaderValue);
    }
}



bool SoaRequest::Save_append_Session()
{
    QString data = WebSessionCurrent+"\n";
    QFile f( _SAVE_SESSION_FILE_ );
	if ( f.open( QFile::Append | QFile::Text ) )
	{
		QTextStream sw( &f );
		sw << data;
		f.close();
		return true;
	}
	return false;
    
}


void SoaRequest::SetSessionId( QString streams )
{

  QString  grepsession = "PD94bWwgdmVyc2lvbj0nMS4wJz8+CjxTOkVudmVsb3BlIHhtbG5zOlM9Imh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3NvYXAvZW52ZWxvcGUvIiA+CiAgICAgPFM6Qm9keT4KICAgICAgICAgIDxuczI6bG9naW5SZXNwb25zZSB4bWxuczpuczI9Imh0dHA6Ly93cy50aWNpbm8tdG91cmlzbS5jaC93c2RsIiA+CiAgICAgICAgICAgICAgIDxyZXR1cm4+CiAgICAgICAgICAgICAgICAgICAgPHRva2VuPjQ2MDAyMDA5ODA3MzAxNDE4NTI8L3Rva2VuPgogICAgICAgICAgICAgICAgICAgIDx1c2VyPgogICAgICAgICAgICAgICAgICAgICAgICAgPGlkPjQ2OTQwPC9pZD4KICAgICAgICAgICAgICAgICAgICAgICAgIDxhY2NvdW50Q3JlYXRpb24+MjAwOC0wMi0yOFQxODoxMTo0MyswMTowMDwvYWNjb3VudENyZWF0aW9uPgogICAgICAgICAgICAgICAgICAgICAgICAgPGphYXNSb2xlPmxpbWl0ZWRSZWFkZXIsaG91c2VSZWFkZXIsYWxwaW5lSHV0UmVhZGVyLGNhbXBncm91bmRSZWFkZXIsaG90ZWxSZWFkZXIseW91dGhIb3N0ZWxSZWFkZXI8L2phYXNSb2xlPgogICAgICAgICAgICAgICAgICAgICAgICAgPGxhc3ROYW1lPlBldGVyIEhvaGw8L2xhc3ROYW1lPgogICAgICAgICAgICAgICAgICAgICAgICAgPGxvZ2luPlBIb2hsPC9sb2dpbj4KICAgICAgICAgICAgICAgICAgICAgICAgIDxwYXNzd29yZD41MWNhZjliZWYyYzc3ZTlmOWU2ZDNkNjE5YzBhMGQ3MDwvcGFzc3dvcmQ+CiAgICAgICAgICAgICAgICAgICAgICAgICA8d29ya3NwYWNlLz4KICAgICAgICAgICAgICAgICAgICA8L3VzZXI+CiAgICAgICAgICAgICAgIDwvcmV0dXJuPgogICAgICAgICAgPC9uczI6bG9naW5SZXNwb25zZT4KICAgICA8L1M6Qm9keT4KPC9TOkVudmVsb3BlPg==";
  ///// fromBase64(grepsession)
     QString errorStr;
     int errorLine, errorColumn, position;
	   if (!doc.setContent(streams,false, &errorStr, &errorLine, &errorColumn)) {
		  emit SendError();
			return;
     }
		QDomElement root = doc.documentElement();
	  QDomElement d1 = root.firstChildElement("S:Body");
	  QDomElement d2 = d1.firstChildElement("ns2:loginResponse");
		QDomElement returner = d2.firstChildElement("return");
		WebSessionCurrent = returner.firstChildElement("token").text().trimmed();
		if (WebSessionCurrent.size() < 1) {
			ResetSession();
		} else {
			Save_append_Session();
     qDebug() << "### SSS " << WebSessionCurrent << " #######session started ";
		}
}


void SoaRequest::ResetSession()
{
	WebSessionCurrent = "00000000000000000000";
	Save_append_Session();
}






LoadSoa::LoadSoa( int nr , QUrl url_send , QDomDocument send_doc  )
	: QHttp(url_send.host(),QHttp::ConnectionModeHttp ,80)
{
     
     url = url_send;
     cid = nr;
     doc = send_doc;
     setHost(url_send.host() , 80);
	   /////////qDebug() << "### parte -> " << url;
}

void LoadSoa::Start()
{
	     QByteArray *bites = new QByteArray();
			 bites->append(doc.toByteArray(2)); 
			 buffer_send = new QBuffer(bites,this);
	     const QString METHOD =  "POST";
       const QString agent = QString("%1_ETV-Vallemaggia-Sincro_%1").arg(cid);
			 header.setRequest(METHOD,url.path(),1,1);
			 header.setValue("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
			 header.setValue("Content-Type","text/xml; charset=utf-8");
			 header.setValue("Host",url.host());
			 header.setValue("User-Agent",agent);
			 connect(this, SIGNAL(done(bool)), this , SLOT(PageReady(bool)));
       Http_id = request(header,buffer_send,0);
       QDomElement root = doc.documentElement();
       root.setAttribute ("Http_id",Http_id);
       root.setAttribute ("C_id",cid);
	
}

void LoadSoa::PageReady( bool error )
{
	  QString errorStr;
    int errorLine, errorColumn, position;
    if (hdoc.setContent(readAll(),false, &errorStr, &errorLine, &errorColumn)) {
			
			 QDomElement root = hdoc.documentElement();
       root.setAttribute ("Http_id",Http_id);
			 
       root.setAttribute ("C_id",cid);
			 root.setAttribute ("host",url.host());
			 root.setAttribute ("path",url.path());
			 root.setAttribute ("entrato_il",QDateTime::currentDateTime().toString());
    } else {
			hdoc.clear();
		}
	emit take(cid,Http_id);
}


void RequestSoa::Setting( QObject *parent , int id , QUrl url_send ,  QDomDocument send_doc )
{
	receiver = parent;
	cid = id;
	url = url_send;
  doc = send_doc;
	setTerminationEnabled(true);
}

void RequestSoa::run()
{
	 Rhttp = new LoadSoa(cid,url,doc);
	 connect(Rhttp, SIGNAL(take(int,int)), receiver , SLOT(childFinished(int,int)));
	 Rhttp->Start();
	 exec();
}


void RequestStreams::Setting( QObject *parent , int id , QUrl url_send ,  DATATYPE e  )
{
	receiver = parent;
	cid = id;
	url = url_send;
  must = e;
	setTerminationEnabled(true);
}

void RequestStreams::run()
{
	 Rhttp = new LoadGet(cid,url,must);
	 connect(Rhttp, SIGNAL(take(int)), receiver , SLOT(stream_in(int)));
	 Rhttp->Start();
	 exec();
}



LoadGet::LoadGet( int nr , QUrl url_send  , DATATYPE e  )
	: QHttp(url_send.host(),QHttp::ConnectionModeHttp ,80)
{
     url = url_send;
     cid = nr;
     wait_on = e;
     setHost(url_send.host() , 80);
	    qDebug() << "### parte -> " << url;
}

void LoadGet::Start()
{
	     const QString METHOD =  "GET";
       const QString agent = QString("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
			 header.setRequest(METHOD,url.path(),1,1);
			 header.setValue("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
			 header.setValue("Host",url.host());
			 header.setValue("User-Agent",agent);
			 connect(this, SIGNAL(done(bool)), this , SLOT(ImageReady(bool)));
       Http_id = request(header,0,0);
}

void LoadGet::ImageReady( bool error )
{
	///////////qDebug() << "### in -> " << cid;
	
    if (!error) {
        if (wait_on == STREAM_PNG || wait_on == STREAM_JPG || wait_on == STREAM_GIF) {
        resultimage.loadFromData(readAll());
                if (!resultimage.isNull()) {
                    emit take(cid);
                }
        
        } else {
            emit take(cid);
        }
    }
}



















